namespace CinemaDirector
{
	public class GlobalItemTrack : GlobalTrack
	{
		public CinemaGlobalEvent[] Events
		{
			get
			{
				return GetComponentsInChildren<CinemaGlobalEvent>();
			}
		}

		public CinemaGlobalAction[] Actions
		{
			get
			{
				return GetComponentsInChildren<CinemaGlobalAction>();
			}
		}

		public override TimelineItem[] TimelineItems
		{
			get
			{
				CinemaGlobalEvent[] events = Events;
				CinemaGlobalAction[] actions = Actions;
				TimelineItem[] array = new TimelineItem[events.Length + actions.Length];
				for (int i = 0; i < events.Length; i++)
				{
					array[i] = events[i];
				}
				for (int j = 0; j < actions.Length; j++)
				{
					array[j + events.Length] = actions[j];
				}
				return array;
			}
		}

		public override void Initialize()
		{
			elapsedTime = -1f;
			TimelineItem[] array = TimelineItems;
			foreach (TimelineItem timelineItem in array)
			{
				timelineItem.Initialize();
			}
		}

		public override void UpdateTrack(float time, float deltaTime)
		{
			float num = elapsedTime;
			elapsedTime = time;
			CinemaGlobalEvent[] events = Events;
			foreach (CinemaGlobalEvent cinemaGlobalEvent in events)
			{
				if (num < cinemaGlobalEvent.Firetime && elapsedTime >= cinemaGlobalEvent.Firetime)
				{
					cinemaGlobalEvent.Trigger();
				}
				if (num >= cinemaGlobalEvent.Firetime && elapsedTime < cinemaGlobalEvent.Firetime)
				{
					cinemaGlobalEvent.Reverse();
				}
			}
			CinemaGlobalAction[] actions = Actions;
			foreach (CinemaGlobalAction cinemaGlobalAction in actions)
			{
				if (num < cinemaGlobalAction.Firetime && elapsedTime > cinemaGlobalAction.Firetime && elapsedTime < cinemaGlobalAction.Firetime + cinemaGlobalAction.Duration)
				{
					cinemaGlobalAction.Trigger();
				}
				else if (elapsedTime > cinemaGlobalAction.Firetime && elapsedTime < cinemaGlobalAction.Firetime + cinemaGlobalAction.Duration)
				{
					float time2 = time - cinemaGlobalAction.Firetime;
					cinemaGlobalAction.UpdateTime(time2, deltaTime);
				}
				else if (num < cinemaGlobalAction.Firetime + cinemaGlobalAction.Duration && elapsedTime >= cinemaGlobalAction.Firetime + cinemaGlobalAction.Duration)
				{
					cinemaGlobalAction.End();
				}
				else if (num > cinemaGlobalAction.Firetime && num <= cinemaGlobalAction.Firetime + cinemaGlobalAction.Duration && elapsedTime < cinemaGlobalAction.Firetime)
				{
					cinemaGlobalAction.ReverseTrigger();
				}
				else if (num > cinemaGlobalAction.Firetime + cinemaGlobalAction.Duration && elapsedTime > cinemaGlobalAction.Firetime && elapsedTime <= cinemaGlobalAction.Firetime + cinemaGlobalAction.Duration)
				{
					cinemaGlobalAction.ReverseEnd();
				}
			}
		}

		public override void SetTime(float time)
		{
			float deltaTime = time - elapsedTime;
			CinemaGlobalAction[] actions = Actions;
			foreach (CinemaGlobalAction cinemaGlobalAction in actions)
			{
				float time2 = time - cinemaGlobalAction.Firetime;
				cinemaGlobalAction.SetTime(time2, deltaTime);
			}
		}

		public override void Stop()
		{
			TimelineItem[] array = TimelineItems;
			foreach (TimelineItem timelineItem in array)
			{
				timelineItem.Stop();
			}
		}
	}
}
